const fs = require('fs');
const fsp = require('fs/promises');
const path = require('path');
const { existsSync } = fs;
const { readFile } = fsp;


var baseUrl = process.cwd();  //命令行所在目录
var siteUrl = "./site" // 站点的默认位置

function render(url) {
    console.log(path.join(baseUrl, siteUrl, url));
    var isExist = existsSync(path.join(baseUrl, siteUrl, url));
    console.log("isExist", isExist);
    if (!isExist) {
        var err = new Error("Not Found");
        throw err;
    }

    return readFile(path.join(baseUrl, siteUrl, url));
}

function static(url) {
    siteUrl = url;
}


module.exports = {
    render,
    static,
}
